<?php
/**
* Copyright 2009 Waag Society <http://www.waag.org>
* This file is part of Annotrax.
*
* Annotrax is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* Annotrax is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Annotrax.
* If not, see http://www.gnu.org/licenses/gpl.html
*/

?>
<?php
class Default_Form_User extends Zend_Form{
    private $user;

    public function init(){
        $this->setMethod( 'post' );

        $inputs = array(
            'Nick name:' => 'nickname',
            'Real name:' => 'fullname',
            'Email'      => 'email'
        );

        $user = $this->getUser();

        foreach( $inputs as $label => $name ){
            $value = 'Unknown';

            if( null !== $user->$name ){
                $value = $user->$name;
            }

            $e = new Zend_Form_Element_Text($name, array(
                'label'     => $label,
                'required'  => true,
                'value'     => $value
            ));

            $e->addValidators(array(
                array('NotEmpty', true),
                array('stringLength', false, array(5, 64)),
            ));

            $e->addFilters(array(
                array('stringTrim', true)
            ));

            if( $name === 'email' ){
                $e->addValidator( 'EmailAddress', true );
            }

            $this->addElement( $e );
        }

        $this->addElement( 'submit', 'Submit' );

        return $this;
    }

    public function getUser(){
        if( null === $this->user ){
            $this->user = At_Factory::user();
        }
        return $this->user;
    }


}
